<template>
  <div class="app-container">

    <!-- 添加或修改科技人员对话框 -->
    <vxe-modal :title="title" v-model="open" width="60%" append-to-body showFooter esc-closable show-zoom resize>
      <el-form ref="formDialog" :model="form" :rules="rules" label-width="100px">
        <el-tabs type="border-card" v-model="activeName">
          <!-- 基本资料 -->
          <el-tab-pane name="jbZl" :lazy=true>
            <span slot="label"><i class="el-icon-date"></i> 基本资料</span>
            <div v-if="activeName === 'jbZl'" style="height: 70vh; overflow-y: auto;">
              <el-card shadow="never">
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="姓名：" prop="name">
                      <el-input v-model="form.name" placeholder="请输入姓名"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="性别：" prop="sex">
                      <el-select v-model="form.sex" placeholder="请选择性别">
                        <el-option
                          v-for="dict in dict.type.sys_user_sex"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="身份证号：" prop="sfzh">
                      <el-input v-model="form.sfzh" placeholder="请输入身份证号"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="出生日期：" prop="csrq">
                      <el-date-picker clearable
                                      v-model="form.csrq"
                                      type="date"
                                      style="width: 100%;"
                                      value-format="yyyy-MM-dd"
                                      placeholder="请选择出生日期">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="职称：" prop="zc">
                      <el-select v-model="form.zc" placeholder="请选择职称">
                        <el-option
                          v-for="dict in dict.type.rcpt_zc"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="职务：" prop="zw">
                      <el-input v-model="form.zw" placeholder="请输入职务"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="学历：" prop="xl">
                      <el-input v-model="form.xl" placeholder="请输入学历"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="毕业院校：" prop="byYx">
                      <el-input v-model="form.byYx" placeholder="请输入毕业院校"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="所学专业：" prop="sxZy">
                      <el-input v-model="form.sxZy" placeholder="请输入所学专业"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="熟悉领域：" prop="sxLy">
                      <el-select v-model="form.sxLy" placeholder="请选择熟悉领域">
                        <el-option
                          v-for="dict in dict.type.rcpt_sxly"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="人员分类：" prop="ryFl">
                      <el-select v-model="form.ryFl" placeholder="请选择人员分类">
                        <el-option
                          v-for="dict in dict.type.rcpt_ryfl"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="是否专家：" prop="sfZj">
                      <el-select v-model="form.sfZj" placeholder="请选择是否专家">
                        <el-option
                          v-for="dict in dict.type.rcpt_sf"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="电话：" prop="phone">
                      <el-input v-model="form.phone" placeholder="请输入电话"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="QQ：" prop="qq">
                      <el-input v-model="form.qq" placeholder="请输入QQ"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="12">
                    <el-form-item label="是否在职：" prop="sfZz">
                      <el-select v-model="form.sfZz" placeholder="请选择是否在职">
                        <el-option
                          v-for="dict in dict.type.rcpt_sf"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="所属单位：" prop="ssDw">
                      <el-input v-model="form.ssDw" placeholder="请输入所属单位" @focus="openDeptTree" :suffix-icon="'el-icon-search'"/>
                      <!--                      <el-input v-model="form.ssDw" placeholder="请输入所属单位" />-->
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-form-item label="专业特长：" prop="zyTc">
                  <el-input :rows="5" v-model="form.zyTc" type="textarea" placeholder="请输入内容"/>
                </el-form-item>
                <el-row :gutter="24">
                  <el-col :span="15">
                    <el-form-item label="个人简介：" prop="grJj">
                      <el-input :rows="9" v-model="form.grJj" type="textarea" placeholder="请输入内容"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="证件照上传：" prop="zjZ">
                      <image-upload v-model="form.zjZ"/>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-card>
            </div>
          </el-tab-pane>
          <!-- 科技人员工作履历信息 -->
          <el-tab-pane name="gzLv" :lazy=true>
            <span slot="label"><i class="el-icon-date"></i> 科技人员工作履历信息</span>
            <div v-if="activeName === 'gzLv'" style="height: 70vh; overflow-y: auto;">
              <el-row :gutter="10" class="mb8">

                <el-col :span="1.5">
                  <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddKjryGzlv">添加</el-button>
                </el-col>
                <el-col :span="1.5">
                  <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteKjryGzlv">删除
                  </el-button>
                </el-col>
              </el-row>
              <el-table :header-cell-style="{background:'#d0cece',color:'#000000',fontWeight:'bold'}"
                        :data="kjryGzlvList" :row-class-name="rowKjryGzlvIndex"
                        @selection-change="handleKjryGzlvSelectionChange" ref="kjryGzlv">
                <el-table-column type="selection" width="50" align="center"/>
                <el-table-column label="序号" align="center" prop="index" width="50"/>
                <el-table-column label="开始时间" align="center" prop="ksTime" width="170">
                  <template slot-scope="scope">
                    <el-date-picker style="width: 90%" clearable v-model="scope.row.ksTime" type="date"
                                    value-format="yyyy-MM-dd" placeholder="开始时间"/>
                  </template>
                </el-table-column>
                <el-table-column label="截止时间" align="center" prop="jzTime" width="170">
                  <template slot-scope="scope">
                    <el-date-picker style="width: 90%" clearable v-model="scope.row.jzTime" type="date"
                                    value-format="yyyy-MM-dd" placeholder="截止时间"/>
                  </template>
                </el-table-column>
                <el-table-column label="单位/部门" align="center" prop="dwBm">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.dwBm" placeholder="请输入单位/部门"/>
                  </template>
                </el-table-column>
                <el-table-column label="职务" align="center" prop="zw">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.zw" placeholder="请输入职务"/>
                  </template>
                </el-table-column>
                <el-table-column label="负责内容" align="center" prop="fzNr">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.fzNr" placeholder="请输入负责内容"/>
                  </template>
                </el-table-column>
              </el-table>

            </div>
          </el-tab-pane>
          <!-- 附件资料 -->
          <el-tab-pane name="fjZl" :lazy=true>
            <span slot="label"><i class="el-icon-date"></i> 附件资料</span>
            <div v-if="activeName === 'fjZl'" style="height: 70vh; overflow-y: auto;">
              <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                  <!-- 上传按钮 -->
                  <el-button size="mini" icon="el-icon-upload" type="primary" @click="kjryFjShangChuan">上传</el-button>
                </el-col>
                <el-col :span="1.5">
                  <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteKjryFj">删除</el-button>
                </el-col>
              </el-row>
              <el-table :header-cell-style="{background:'#d0cece',color:'#000000',fontWeight:'bold'}"
                        :data="kjryFjList" :row-class-name="rowKjryFjIndex"
                        @selection-change="handleKjryFjSelectionChange"
                        ref="kjryFj">
                <el-table-column type="selection" width="50" align="center"/>
                <el-table-column label="序号" align="center" prop="index" width="50"/>
                <el-table-column label="文件名称" show-overflow-tooltip align="center" prop="fileName"
                                 :formatter="getFileNames"/>
                <el-table-column label="文件大小" align="center" prop="fileSize" width="130"/>
                <el-table-column label="上传时间" align="center" prop="scTime" width="110"/>
                <el-table-column label="上传人" align="center" prop="scUser" width="130"/>
                <el-table-column label="操作" width="120" align="center" class-name="small-padding fixed-width">
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-edit"
                      @click="handleDownload(scope.row)"
                    >下载
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-tab-pane>
        </el-tabs>
      </el-form>
      <div slot="footer" class="dialog-footer dialog-footer-center">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </vxe-modal>

    <!-- 选择部门弹窗组件 -->
    <dept-tree ref="deptOpen"/>

    <!-- 科技人员附件上传弹窗 -->
    <vxe-modal title="附件上传" v-model="fjShangChuan" width="25%" append-to-body @close="fjClose" showFooter>
      <el-upload
        align="center"
        class="upload-demo"
        multiple
        :action="uploadFileUrl"
        :before-upload="handleBeforeUpload"
        :file-list="fileList"
        :limit="20"
        :on-error="handleUploadError"
        :on-exceed="handleExceed"
        :on-success="handleUploadSuccess"
        :headers="headers"
        ref="fileUpload"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip" slot="tip">
          请上传
          <template> 大小不超过 <b style="color: #f56c6c">{{ 50 }}MB</b></template>
          <template v-if="fileType"> 格式为 <b style="color: #f56c6c">{{ fileType.join("/") }}</b></template>
          的文件
        </div>
      </el-upload>

      <div slot="footer" class="dialog-footer" style="display: flex; justify-content: center;">
        <el-button v-if="allFilesUploaded === false" size="mini" type="primary" @click="fjShangChuan = false">关 闭
        </el-button>
        <el-button v-if="allFilesUploaded === true" size="mini" type="primary" @click="fjShangChuan = false">上传完成, 关闭
        </el-button>
      </div>

    </vxe-modal>

  </div>
</template>

<script>
import {
  addKjry,
  delKjry,
  getKjry,
  getKjryId,
  insertKjryFjByxmsbId,
  listKjry,
  selectKjryFjList,
  selectKjryGzlvByKjryId,
  updateKjry
} from "@/api/kjry/kjry";
import {getToken} from "@/utils/auth";
import JinDu from "@/views/components/liuChengState/jindu";
import {revokeProcess, startTask} from "@/api/activiti/task";
import KjryXq from "@/views/kjry/kjry/components/kjryXq";
import DeptTree from "@/views/components/dept/deptTree";

export default {
  name: "KjRyBj", //科技人员编辑组件
  dicts: ['rcpt_sxly', 'rcpt_ryfl', 'sys_user_sex', 'rcpt_sf', 'process_business_status', 'rcpt_zc'],
  components: {
    DeptTree,
    KjryXq,
    JinDu
  },
  provide() {
    return {
      updateDeptLabel: (val) => {
        this.receivedDeptLabel = val;
        this.form.ssDw = this.receivedDeptLabel;
      },
      updateDeptId:  (val) => {
        this.receivedDeptId = val;
        this.form.deptId = this.receivedDeptId;
      },
    };
  },
  data() {
    return {
      receivedDeptId: null,
      receivedDeptLabel: null,
      activeName: 'jbZl', //默认打开的标签
      selectedRow: null, // 保存当前选中的行
      historyList: [], //历史信息
      xg: false, //判断是新增还是修改 (false新增 true修改)
      allFilesUploaded: false, // 添加这个来追踪所有文件是否上传完成
      fjShangChuan: false, //附件上传弹窗
      kjryIdEdit: "", //要修改的 科技人员id
      uploadFileUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传文件服务器地址
      fileList: [],
      headers: {Authorization: "Bearer " + getToken()},
      number: 0,
      uploadList: [],
      fileType: ["doc", "xls", "ppt", "txt", "pdf", "docx", "zip"],
      getKjryId: null, //从后端获得的科技人员主键UUID
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedKjryFj: [],
      // 工作履历子表选中数据
      checkedKjryGzlv: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 科技人员表格数据
      kjryList: [],
      // 科技人员附件表格数据
      kjryFjList: [],
      // 科技人员工作履历表格数据
      kjryGzlvList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        sxLy: null,
        ryFl: null,
        sfZj: null,
        userId: this.$store.state.user.id,
        deptId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [{required: true, message: "姓名不能为空", trigger: "blur"}],
        sex: [{required: true, message: "性别不能为空", trigger: "change"}],
        sfzh: [{required: true, message: "身份证号不能为空", trigger: "blur"},
          /*{ pattern: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/, message: "身份证号格式不正确", trigger: "blur" }*/],
        csrq: [{required: true, message: "出生日期不能为空", trigger: "blur"}],
        zc: [{required: true, message: "职称不能为空", trigger: "blur"}],
        zw: [{required: true, message: "职务不能为空", trigger: "blur"}],
        xl: [{required: true, message: "学历不能为空", trigger: "blur"}],
        byYx: [{required: true, message: "毕业院校不能为空", trigger: "blur"}],
        sxZy: [{required: true, message: "所学专业不能为空", trigger: "blur"}],
        sxLy: [{required: true, message: "熟悉领域不能为空", trigger: "change"}],
        ryFl: [{required: true, message: "人员分类不能为空", trigger: "change"}],
        sfZj: [{required: true, message: "是否专家不能为空", trigger: "change"}],
        phone: [{required: true, message: "电话不能为空", trigger: "blur"}],
        sfZz: [{required: true, message: "是否在职不能为空", trigger: "change"}],
        ssDw: [{required: true, message: "所属单位不能为空", trigger: "blur"}],
        zyTc: [{required: true, message: "专业特长不能为空", trigger: "blur"}],
        grJj: [{required: true, message: "个人简介不能为空", trigger: "blur"}],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //打开选择部门弹窗组件
    openDeptTree() {
      this.$refs.deptOpen.handleOpen();
    },
    //发起任务
    handleStartTask() {
      const row = this.selectedRow; // 获取当前选中的行
      if (!row) {
        this.$message.error("请先选择一行数据");
        return;
      }
      this.$confirm("是否确认发起申请？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          startTask({businessKey: row.kjryId, businessType: 3}).then(res => {
            this.getList();
            this.$modal.msgSuccess("发起成功");
            this.selectedRow = null
          });
        })
        .catch(() => {
        });
    },
    // 文件下载处理
    handleDownload(row) {
      const resource = row.fileName;
      // 默认方法
      this.$download.resource(resource);
    },
    // 获取文件名原名
    getFileNames(row) {
      // 从路径中提取文件名
      return row.fileName.split('/').pop(); // 返回文件名部分
    },
    //关闭上传附件弹窗后
    fjClose() {
      this.fileList = []
      this.allFilesUploaded = false
    },
    //上传文件之前的钩子
    handleBeforeUpload(file) {
      let that = this;
      // 校检文件类型
      if (this.fileType) {
        const fileName = file.name.split('.');
        const fileExt = fileName[fileName.length - 1];
        const isTypeOk = this.fileType.indexOf(fileExt) >= 0;
        if (!isTypeOk) {
          this.$modal.msgError(`文件格式不正确, 请上传${this.fileType.join("/")}格式文件!`);
          return false;
        }
        // 校检文件大小
        if (this.fileSize) {
          const isLt = file.size / 1024 / 1024 < this.fileSize;
          if (!isLt) {
            this.$modal.msgError(`上传文件大小不能超过 ${this.fileSize} MB!`);
            return false;
          }
        }
        this.$modal.loading("正在上传文件，请稍候...");
        this.number++;
        return true;
      }
    },
    // 对象转成指定字符串分隔
    listToString(list, separator) {
      let strs = "";
      separator = separator || ",";
      for (let i in list) {
        strs += list[i].url + separator;
      }
      return strs !== '' ? strs.substr(0, strs.length - 1) : '';
    },
    // 上传失败
    handleUploadError() {
      this.$modal.msgError("上传文件失败，请重试");
      this.$modal.closeLoading();
    },
    // 文件个数超出
    handleExceed() {
      this.$modal.msgError(`上传文件数量不能超过 ${this.limit} 个!`);
    },
    // 上传成功
    handleUploadSuccess(res, file) {
      let that = this;
      if (res.code === 200) {
        this.uploadList.push({name: res.fileName, url: res.fileName, size: that.formatFileSize(file.size)});
        let xzItemFile = {
          "kjryId": that.getKjryId,
          "fileName": res.fileName,
          "fileSize": that.formatFileSize(file.size)
        };
        let xgItemFile = {
          "kjryId": that.kjryIdEdit,
          "fileName": res.fileName,
          "fileSize": that.formatFileSize(file.size)
        };
        if (this.xg === false) {
          // 点击新增按钮的上传
          insertKjryFjByxmsbId(xzItemFile).then(resFil => {
            that.getKjryFjList();
          })
        } else if (this.xg === true) {
          // 点击修改按钮的上传
          insertKjryFjByxmsbId(xgItemFile).then(resFil => {
            that.getKjryFjList();
          })
        }
        this.uploadedSuccessfully();
      } else {
        this.number--;
        this.$modal.closeLoading();
        this.$modal.msgError(res.msg);
        this.$refs.fileUpload.handleRemove(file);
        this.uploadedSuccessfully();
      }
      this.allFilesUploaded = true
      this.$modal.msgSuccess("上传成功")
      // this.fjShangChuan = false
    },
    getKjryFjList() {
      let that = this;
      if (this.xg === false) {
        //点击新增 上传文件后的文件列表
        selectKjryFjList(that.getKjryId).then(resFileList => {
          that.kjryFjList = resFileList.data;
        })
      } else {
        //点击修改 上传文件后的文件列表
        selectKjryFjList(that.kjryIdEdit).then(resFileList => {
          that.kjryFjList = resFileList.data;
        })
      }
    },
    // 显示文件大小为KB, MB, GB, TB
    formatFileSize(size) {
      if (size === 0) return '0 Bytes';
      const k = 1024;
      const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
      const i = Math.floor(Math.log(size) / Math.log(k));
      return parseFloat((size / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
    },
    // 获取文件名称
    getFileName(name) {
      // 如果是url那么取最后的名字 如果不是直接返回
      if (name.lastIndexOf("/") > -1) {
        return name.slice(name.lastIndexOf("/") + 1);
      } else {
        return name;
      }
    },
    // 上传结束处理
    uploadedSuccessfully() {
      if (this.number > 0 && this.uploadList.length === this.number) {
        this.fileList = this.fileList.concat(this.uploadList);
        this.fileList = this.fileList.map(item => {
          // 使用replace方法去除name中的特定前缀
          item.name = item.name.split('/').pop();
          return item;
        });
        this.uploadList = [];
        this.number = 0;
        this.$emit("input", this.listToString(this.fileList));
        this.$modal.closeLoading();
      }
    },
    kjryFjShangChuan() { //科技人员附件上传按钮
      this.fjShangChuan = true;
    },
    // 查询科技人员列表
    getList() {
      this.loading = true;
      listKjry(this.queryParams).then(response => {
        this.kjryList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 新增表单重置
    reset() {
      this.form = {
        kjryId: this.getKjryId, sort: null, name: null, sex: null,
        sfzh: null, age: null, csrq: null, zc: null, zw: null, xl: null,
        byYx: null, sxZy: null, sxLy: null, ryFl: null, sfZj: null,
        phone: null, qq: null, sfZz: null, ssDw: null, zyTc: null,
        grJj: null, zjZ: null, idWhere: null, createBy: null,
        createTime: null, updateBy: null, updateTime: null, userId: null, deptId: null
      };
      this.kjryFjList = [];
      this.kjryGzlvList = [];
      this.resetForm("formDialog");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      let ids = selection.map(item => item.kjryId)
      if (ids.length === 1) {
        this.ids = ids[0]
      }else {
        this.ids = ids
      }
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.xg = true
      this.reset();
      const kjryId = row.businessKey
      this.kjryIdEdit = row.businessKey
      getKjry(kjryId).then(response => {
        this.form = response.data;
        this.kjryFjList = response.data.kjryFjList;
        this.activeName = 'jbZl'
        this.open = true;
        this.title = "修改科技人员";
      });
      selectKjryGzlvByKjryId(kjryId).then(res => {
        this.kjryGzlvList = res.data.kjryGzlvList;
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["formDialog"].validate(valid => {
        if (valid) {
          this.form.kjryFjList = this.kjryFjList;
          this.form.kjryGzlvList = this.kjryGzlvList;
          if (this.form.idWhere != null) {
            updateKjry(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
              this.xg = false
            });
          } else {
            addKjry(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 科技人员附件序号 */
    rowKjryFjIndex({row, rowIndex}) {
      row.index = rowIndex + 1;
    },
    /** 科技人员附件删除按钮操作 */
    handleDeleteKjryFj() {
      if (this.checkedKjryFj.length === 0) {
        this.$modal.msgError("请先选择要删除的科技人员附件数据");
      } else {
        const kjryFjList = this.kjryFjList;
        const checkedKjryFj = this.checkedKjryFj;
        this.kjryFjList = kjryFjList.filter(function (item) {
          return checkedKjryFj.indexOf(item.index) === -1
        });
      }
    },
    /** 复选框选中数据 */
    handleKjryFjSelectionChange(selection) {
      this.checkedKjryFj = selection.map(item => item.index)
    },
    /** 科技人员工作履历序号 */
    rowKjryGzlvIndex({row, rowIndex}) {
      row.index = rowIndex + 1;
    },
    /** 科技人员工作履历添加按钮操作 */
    handleAddKjryGzlv() {
      let obj = {};
      obj.ksTime = "";
      obj.jzTime = "";
      obj.dwBm = "";
      obj.zw = "";
      obj.fzNr = "";
      this.kjryGzlvList.push(obj);
    },
    /** 科技人员工作履历删除按钮操作 */
    handleDeleteKjryGzlv() {
      if (this.checkedKjryGzlv.length === 0) {
        this.$modal.msgError("请先选择要删除的科技人员工作履历数据");
      } else {
        const kjryGzlvList = this.kjryGzlvList;
        const checkedKjryGzlv = this.checkedKjryGzlv;
        this.kjryGzlvList = kjryGzlvList.filter(function (item) {
          return checkedKjryGzlv.indexOf(item.index) === -1
        });
      }
    },
    /** 复选框选中数据 */
    handleKjryGzlvSelectionChange(selection) {
      this.checkedKjryGzlv = selection.map(item => item.index)
    },
  }
};
</script>

<style scoped>
/*/deep/ .el-form-item__error{*/
/*  color: #ff4949;*/
/*  font-size: 12px;*/
/*  line-height: 0.35;*/
/*  padding-top: 4px;*/
/*  position: absolute;*/
/*  top: 100%;*/
/*  left: 0;*/
/*}*/
/* 按钮居中 */
/*.dialog-footer-center {*/
/*  display: flex;*/
/*  justify-content: center;*/
/*}*/
</style>
